<script setup>
import { useRouter } from 'vue-router';
const router = useRouter();
import { ref } from 'vue';
import axios from "axios";
import {showToast} from "vant";
import {get} from "../../util/request.js";
const loading = ref(false);
const finished = ref(false);
const collections = ref([{

}]);
const active = ref('0');

const onClickLeft1=()=>{
  router.push('/my')
}

const changeTab = () => {
  console.log(active.value);
  get(`question/findAllQuestionByType?type=${active.value}`).then((response) => {
    console.log("原始响应数据:", JSON.stringify(response));
    // 直接使用响应体
    const { code, msg, data } = response;
    // 检查code值并处理
    if (code === 0) {
      console.log("查询成功，数据:", JSON.stringify(data));
      showToast("查询成功");
      collections.value = data; // 直接赋值给collections
    } else {
      console.error("查询失败，错误信息:", msg);
      showToast("查询失败: " + msg);
    }
  }).catch((error) => {
    // 处理请求失败的情况
    console.error("请求失败:", error);
    showToast("请求失败，请稍后再试");
  });
};

</script>

<template>
<h1>我叫喻文波</h1>


    <van-nav-bar
        title="错题集"
        left-text="返回"
        left-arrow
        @click-left="onClickLeft1"
    />
    <van-tabs v-model:active="active" @change="changeTab">
      <van-tab title="所有错题集" neme="0">
          <van-list
              v-model="loading"
              :finished="finished"
              finished-text="没有更多了"

          >
            <van-cell v-for="(collection, index) in collections"
                      :key="index" :title="collection.questionId"
                      :label="collection.wrongDateTime" is-link
                      :value="collection.wrongAnswer"
            >
            </van-cell>
          </van-list>
      </van-tab>
      <van-tab title="大综合" name="1">
        <van-cell-group>
          <van-list>

            <van-cell v-for="(collection, index) in collections"
                      :key="index" :title="collection.questionId"
                      :label="collection.wrongDateTime" is-link
                      :value="collection.wrongAnswer"
            >
            </van-cell>
          </van-list>
        </van-cell-group>
      </van-tab>
      <van-tab title="英语" name="2">
        <van-cell-group>
          <van-list>
            <van-cell v-for="(collection, index) in collections"
                      :key="index" :title="collection.questionId"
                      :label="collection.wrongDateTime" is-link
                      :value="collection.wrongAnswer"
            >
            </van-cell>
          </van-list>
        </van-cell-group>
      </van-tab>
      <van-tab title="政治" name="3">
        <van-cell-group>
          <van-list>

            <van-cell v-for="(collection, index) in collections"
                      :key="index" :title="collection.questionId"
                      :label="collection.wrongDateTime" is-link
                      :value="collection.wrongAnswer"
            >
            </van-cell>
          </van-list>
        </van-cell-group>
      </van-tab>
    </van-tabs>


</template>

<style scoped>

</style>